<template>
  <div class="app-container home">
    <h1>我的持仓</h1>

    <el-table
      :data="positionData"
      height="250"
      border
      @row-click="handleRowClick"
      style="width: 55%">
      <el-table-column
        prop="sname"
        label="股票名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="symbol"
        label="股票编码"
        width="180">
      </el-table-column>
      <el-table-column
        prop="currentRate"
        label="成交价格"
        width="180">
      </el-table-column>
      <el-table-column
        prop="trade"
        label="当前价格"
        width="180">
      </el-table-column>
      <el-table-column
        prop="priceChange"
        label="涨幅"
        width="180">
        <template v-slot="scope">
          <span :style="{ color: scope.row.priceChange < 0 ? 'green' : 'red' }">{{ scope.row.priceChange }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {getMyPosition} from "@/api/stock/stock";

export default {
  name: "PositionView",
  data(){
    return{
      positionData:[]
    }
  },methods:{
    myPosition(){
      getMyPosition().then(res=>{
        this.positionData = res.data;
      })
    },handleRowClick(row, event, column){
      //alert(row.symbol)
      this.$router.push({path:"/stock/klinechart",query:{symbol:row.symbol,trade:row.trade}})
    }
  },created() {
      this.myPosition()
  }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>
